package qnaaction;

import qnainterceptor.BoardDaoAware;
import qnautil.BoardDAO;
import qnautil.BoardVO;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.opensymphony.xwork2.Preparable;

public class ModifyAction extends ActionSupport implements Preparable, ModelDriven, BoardDaoAware {
	private BoardVO vo;
	private BoardDAO dao;
	
	public void setBoardDao(BoardDAO dao){
		this.dao = dao;
	}
	
	public BoardVO getVo() {
		return vo;
	}

	public void setDao(BoardDAO dao) {
		this.dao = dao;
	}

	public void prepare() throws Exception {
		vo = new BoardVO();
	}
	
	public Object getModel(){
		return vo;
	}
	
	public void validate(){
		if (vo == null || vo.getWriter() == null || vo.getWriter().trim().equals("")){
			this.addFieldError("writerEmptyError", "�ۼ��ڸ� �Է��ϼ���.");
		}
		else if (vo == null || vo.getPasswd() == null || vo.getPasswd().trim().equals("")){
			this.addFieldError("passwdEmptyError", "�н����带 �Է��ϼ���.");
		}
		else if (vo == null || vo.getTitle() == null || vo.getTitle().trim().equals("")){
			this.addFieldError("passwdEmptyError", "������ �Է��ϼ���.");
		}
		else if (vo == null || vo.getContent() == null || vo.getContent().trim().equals("")){
			this.addFieldError("contentEmptyError", "������ �Է��ϼ���.");
		}
	}
	
	public String execute() throws Exception {
		System.out.println("modify vo="+vo);
		dao.Modify(vo);
		return SUCCESS;
	}
}
